/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cubelabs.nexus.service;

import cubelabs.nexus.dao.CategoryDAO;
import cubelabs.nexus.dao.SessionDAO;
import cubelabs.nexus.dao.UserDAO;
import cubelabs.nexus.domain.SearchRequest;
import cubelabs.nexus.domain.SessionDTO;
import cubelabs.nexus.domain.UserDTO;
import cubelabs.nexus.entity.Category;
import cubelabs.nexus.entity.Session;
import cubelabs.nexus.entity.User;
import cubelabs.nexus.utils.GenericUtils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author chaitanya
 */

@Service
public class SearchService {
    @Autowired
    private CategoryDAO categoryDAO;
    
    @Autowired
    private UserDAO userDAO;
    
    
    @Autowired
    private SessionDAO sessionDao;
    
    @Transactional
    public List<UserDTO> fetchExperts(SearchRequest searchRequest){
        List<User> userList= userDAO.searchUsers(searchRequest.getCategorys(), searchRequest.getTime(),searchRequest.getCost(), searchRequest.getRating(),searchRequest.getWeekDays(), searchRequest.getLimit());
        return GenericUtils.getUserDTO(userList);
    }

    @Transactional
    public List<SessionDTO> fetchExpertTalks(SearchRequest searchRequest) {
        List<Session> sessions = sessionDao.searchExpertTalks(searchRequest.getCategorys(), searchRequest.getCost(), searchRequest.getRating(), searchRequest.getStartTime(), searchRequest.getEndTime(), searchRequest.getLimit());
        List<SessionDTO> sessionDTOs = new ArrayList<SessionDTO>();
        if (sessions != null) {
            for (Session session : sessions) {
                SessionDTO sessionDTO = GenericUtils.convertSession(session);
                sessionDTO.setExpertDTO(GenericUtils.getUserDTO(session.getExpert()));
                sessionDTOs.add(sessionDTO);
            }
        }
        return sessionDTOs;
    }
}
